package com.wk.code.wkserver.controller.admin;


import com.wk.code.wkserver.response.admin.RoleListResponse;
import com.wk.code.wkserver.response.result.R;
import com.wk.code.wkserver.entity.Role;
import com.wk.code.wkserver.request.admin.RoleRequest;
import com.wk.code.wkserver.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 角色控制层
 *
 * @author wq
 * @date 2021-07-12 14:42:27
 */
@RestController
@AllArgsConstructor
@RequestMapping("admin/role")
@Api(tags = "admin-系统角色管理")
public class AdminRoleController {

    private final IRoleService roleService;

    /**
     * 角色集合
     *
     * @return R
     */
    @ApiOperation(value = "角色集合", notes = "角色集合")
    @PostMapping("options")
    public R<List<Role>> roles() {
        return R.success(roleService.list());
    }


    /**
     * 添加角色
     *
     * @param req 请求参数
     * @return R
     */
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("add")
    public R<?> add(@RequestBody RoleRequest req) {
        roleService.addRole(req);
        return R.success();
    }

    /**
     * 更新
     *
     * @param req 请求参数
     * @return R
     */
    @ApiOperation(value = "更新", notes = "更新")
    @PostMapping("update")
    public R<Void> update(@RequestBody RoleRequest req) {
        roleService.updateRole(req);
        return R.success();
    }

    /**
     * 删除
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("del/{id}")
    public R<?> del(@PathVariable Integer id) {
        roleService.delRole(id);
        return R.success();
    }


    /**
     * 列表
     *
     * @return R
     */
    @ApiOperation(value = "列表", notes = "列表")
    @PostMapping("list")
    public R<?> list() {
        List<RoleListResponse> list = roleService.findRoleList();
        return R.success(list);
    }
}
